# Build recipe for asciidoctor.
#
# Copyright (C) 2019, 2021-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=asciidoctor
version=2.0.17
pkgname=ruby-${program}
release=1

# Define a category for the output of the package name
pkgcategory=ruby

tarname=${program}-${version}.gem

# Remote source(s)
fetch=https://rubygems.org/downloads/$tarname

description="
Asciidoctor is a fast, open source text processor.

It converts AsciiDoc content to HTML5, DocBook, PDF, and other formats.
Asciidoctor is written in Ruby and runs on all major operating systems.
"

homepage=https://asciidoctor.org
license=MIT

build()
{
    # Figure out directory for Ruby Gems
    _gemdir="$(ruby -W0 -e 'puts Gem.default_dir')"

    if test -z "_$gemdir"
    then
        echo "recipe: Error: the _gemdir variable is empty." 1>&2
        exit 1
    fi

    mkdir -p "${destdir}/${_gemdir}" "${destdir}/usr/bin"

    gem install \
     --ignore-dependencies \
     --no-user-install \
     --backtrace --verbose \
     --install-dir "${destdir}/${_gemdir}" \
     --bindir "${destdir}/usr/bin" \
     "${tardir}/$tarname"
}

